package com.wanchuang.hepos.ui.page.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;

import com.wanchuang.hepos.R;
import com.wanchuang.hepos.bridge.request.HomeRequestViewModel;
import com.wanchuang.hepos.bridge.state.home.ChuZhangDetailViewModel;
import com.wanchuang.hepos.bridge.state.home.TiXianDetailViewModel;
import com.wanchuang.hepos.databinding.FragmentChuZhangDetailBinding;
import com.wanchuang.hepos.databinding.FragmentTiXianDetailBinding;
import com.wanchuang.hepos.ui.base.BaseFragment;

/**
 * 文件名 : HomeRootFragment
 * 创建者 : MangoWang
 * 创建日期 : 2019/12/24 16:20
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */
public class ChuZhangDetailFragment extends BaseFragment {


    private FragmentChuZhangDetailBinding mBinding;
    private ChuZhangDetailViewModel mViewModel;
    private HomeRequestViewModel mRequestViewModel;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mViewModel = ViewModelProviders.of(this).get(ChuZhangDetailViewModel.class);
        mRequestViewModel = ViewModelProviders.of(this).get(HomeRequestViewModel.class);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_chu_zhang_detail, container, false);
        mBinding = FragmentChuZhangDetailBinding.bind(view);
        mBinding.setClick(new ClickProxy());
        mBinding.setVm(mViewModel);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mRequestViewModel.getErrorString().observe(this, s -> {
            hideProgress();
            showShortToast(s);
        });
        mRequestViewModel.getResultString().observe(this, s -> {
            hideProgress();
            showShortToast(s);
        });

    }

    @Override
    public void loadInitData() {
        super.loadInitData();
    }

    public class ClickProxy {
        public void back() {
            nav().navigateUp();
        }


    }

    @Override
    public void onHiddenChanged(boolean hidden) { }
}
